<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file='base/common_header'}
</head>

<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-input-inline layui-show-xs-block">
                            <button type="button" class="layui-btn" onclick="xadmin.open('添加问题','/admin/topic/saveQuestion?topic_id={$topic_id}','','',true)">
                                <i class="layui-icon"></i>添加问题</button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>题目名称</th>
                            <th>排序</th>
                            <th>创建时间</th>
                            <th>操作</th></tr>
                        </thead>
                        <tbody>
                        {volist name='data' id='topic'}
                        <tr>
                            <td>{$topic.id}</td>
                            <td>{$topic.question}</td>
                            <td>
                                {$topic.question_sort}
                            </td>
                            <td>
                                {$topic.created_at|date="Y-m-d H:i:s"}
                            </td>
                            <td class="td-manage">
                                <a class="layui-btn layui-btn-xs" title="编辑" onclick="xadmin.open('编辑问题','/admin/topic/saveQuestion?id={$topic.id}&topic_id={$topic.topic_id}','','',true)" href="javascript:;">
                                    编辑</a>
                                <a title="删除" class="layui-btn layui-btn-xs layui-btn-danger" onclick="topic_del(this,'{$topic.id}')" href="javascript:;">
                                    删除</a>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    function topic_del(obj, id) {
        layer.confirm('确认要删除吗？',
            function(index) {
                //发异步删除数据
                $.post('/admin/topic/dealAttr',{id:id,type:1},function (data) {
                    console.log(data)
                    if(data.error_code == 0){
                        layer.msg('操作成功!', {
                            icon: 1,
                            time: 1000
                        },function () {
                            window.location.reload()
                        });
                    }else{
                        layer.msg('操作失败!', {
                            icon: 1,
                            time: 1000
                        });
                    }
                },"json")

            });
    }
</script>
</html>